using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using DG.Tweening;

public class GameManagerTop : MonoBehaviour
{
    public GameObject ball, ballList, cam, cupmid, cupup;
    public TextMesh startNumberText;
    public int startNumber, temple;
    public Transform cupTrans;
    public CreateBall createBall;
    public GameManagerLow managerLow;
    public DestroyBall destroyBall;
    

    void Start()
    {
        startNumberText.text = startNumber.ToString();
        Tweener tweener = cupup.transform.DOLocalRotate(new Vector3(0, 0, -100), 1f);
        createBall.enabled = true;

    }

    void Update()
    {
        if (Input.GetMouseButton(0) && !EventSystem.current.IsPointerOverGameObject())
        {
            Vector3 screenPos = Camera.main.WorldToScreenPoint(cupTrans.transform.position);
            Vector3 mousePos = Input.mousePosition;
            mousePos.z = screenPos.z;
            mousePos.y = screenPos.y;
            Vector3 worldPos = Camera.main.ScreenToWorldPoint(mousePos);
            if (worldPos.x > 2)
            {
                worldPos.x = 2;
            }
            if (worldPos.x < -2.5)
            {
                worldPos.x = -2.5f;
            }
            cupTrans.position = worldPos;
        }


        destroyBall.timer += Time.deltaTime;
        


        if (destroyBall.timer >= 5f)
        {
            Tweener tweener1 = cam.transform.DOLocalMoveY(-8.5f, 2f);
            Tweener tweener2 = cupmid.transform.DOLocalMoveY(-4.5f, 2f);
            temple = destroyBall.getNumber;
            Destroy(destroyBall);


            if (Input.GetMouseButtonDown(0))
            {
                managerLow.enabled = true;
                this.enabled = false;
            }
        }
    }


}
